package com.ruoyi.analysis.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.analysis.domain.ProductAnalysisPiece;
import com.ruoyi.analysis.service.IProductAnalysisPieceService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工件生产数据Controller
 * 
 * @author ruoyi
 * @date 2022-12-12
 */
@Controller
@RequestMapping("/analysis/piece")
public class ProductAnalysisPieceController extends BaseController
{
    private String prefix = "analysis/piece";

    @Autowired
    private IProductAnalysisPieceService productAnalysisPieceService;

    @RequiresPermissions("analysis:piece:view")
    @GetMapping()
    public String piece()
    {
        return prefix + "/piece";
    }

    /**
     * 查询工件生产数据列表
     */
    @RequiresPermissions("analysis:piece:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductAnalysisPiece productAnalysisPiece)
    {
        startPage();
        List<ProductAnalysisPiece> list = productAnalysisPieceService.selectProductAnalysisPieceList(productAnalysisPiece);
        return getDataTable(list);
    }

    /**
     * 导出工件生产数据列表
     */
    @RequiresPermissions("analysis:piece:export")
    @Log(title = "工件生产数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductAnalysisPiece productAnalysisPiece)
    {
        List<ProductAnalysisPiece> list = productAnalysisPieceService.selectProductAnalysisPieceList(productAnalysisPiece);
        ExcelUtil<ProductAnalysisPiece> util = new ExcelUtil<ProductAnalysisPiece>(ProductAnalysisPiece.class);
        return util.exportExcel(list, "工件生产数据数据");
    }

    /**
     * 新增工件生产数据
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工件生产数据
     */
    @RequiresPermissions("analysis:piece:add")
    @Log(title = "工件生产数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductAnalysisPiece productAnalysisPiece)
    {
        return toAjax(productAnalysisPieceService.insertProductAnalysisPiece(productAnalysisPiece));
    }

    /**
     * 修改工件生产数据
     */
    @RequiresPermissions("analysis:piece:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductAnalysisPiece productAnalysisPiece = productAnalysisPieceService.selectProductAnalysisPieceById(id);
        mmap.put("productAnalysisPiece", productAnalysisPiece);
        return prefix + "/edit";
    }

    /**
     * 修改保存工件生产数据
     */
    @RequiresPermissions("analysis:piece:edit")
    @Log(title = "工件生产数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductAnalysisPiece productAnalysisPiece)
    {
        return toAjax(productAnalysisPieceService.updateProductAnalysisPiece(productAnalysisPiece));
    }

    /**
     * 删除工件生产数据
     */
    @RequiresPermissions("analysis:piece:remove")
    @Log(title = "工件生产数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productAnalysisPieceService.deleteProductAnalysisPieceByIds(ids));
    }
}
